
package com.innovamed.websocket.utils.queue;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.innovamed.websocket.utils.server.ServerConfig;

import cn.hutool.core.net.NetUtil;


/**
 * Copyright: Copyright (c)  Jun_Zhou
 *
 * @PackageName:com.innovamed.websocket.utils.queue
 * @Description: 默认的路由Key生成工具类;
 * @version: v1.0.0
 * @author: JunZhou
 * @Email: 1769676159@qq.com
 * @Site: CERNO
 * @date: 2019/8/25 9:12
 */
@Component
public class RoutingKeyGenerator
{
	
	@Value("${spring.application.name}")
	private String						appName;
	
	@Autowired
	private ServerConfig				serverConfig;
	
	private static RoutingKeyGenerator	ROUTING_KEY_GENERATOR_HOLDER;
	
	@PostConstruct
	public void initIns()
	{
		ROUTING_KEY_GENERATOR_HOLDER = this;
	}
	
	/**
	 * 生成默认的路由key;
	 * @return
	 */
	public static String generateDefaultRouteKey()
	{
		String appName = ROUTING_KEY_GENERATOR_HOLDER.appName;
		String serverHostStr = NetUtil.getLocalhostStr();
		int serverPort = ROUTING_KEY_GENERATOR_HOLDER.serverConfig.getServerPort();
		String defaultRouteKey = appName + "_" + serverHostStr + "_" + serverPort;
		return defaultRouteKey;
	}
	
}
